const axios = require('axios')

async function testLoginAPI () {
  try {
    console.log('🔑 测试登录API...\n')

    const loginData = {
      emailOrUsername: 'test@example.com',
      password: '123456'
    }

    console.log('📤 发送登录请求...')
    console.log('请求数据:', loginData)

    const response = await axios.post(
      'http://localhost:3000/api/auth/login',
      loginData,
      {
        headers: {
          'Content-Type': 'application/json'
        },
        timeout: 5000
      }
    )

    console.log('\n✅ 登录成功！')
    console.log('响应状态:', response.status)
    console.log('响应数据:', JSON.stringify(response.data, null, 2))
  } catch (error) {
    console.error('\n❌ 登录失败！')

    if (error.response) {
      console.log('状态码:', error.response.status)
      console.log('错误信息:', error.response.data)
    } else if (error.request) {
      console.log('请求错误:', error.message)
    } else {
      console.log('其他错误:', error.message)
    }
  }
}

testLoginAPI()
